package com.twt.common.pojo;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class Result<T> {
    private Integer code;
    private String message;
    private T data;


    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }


    public static <T> Result<T> build(T body, ResultCodeEnum codeEnum) {
        return new Result<>(codeEnum.getCode(), codeEnum.getMsg(), body);
    }

    public static <T> Result<T> ok(T data) {
        Result<T> build = Result.build(data, ResultCodeEnum.SUCCESS);
        return build;
    }

    public static Result ok() {
        return Result.ok(null);
    }


    public static <T> Result<T> fail() {
        return Result.build(null, ResultCodeEnum.FAIL);
    }

    public static <T> Result<T> fail(ResultCodeEnum resultCodeEnum) {
        return Result.build(null, resultCodeEnum);
    }

    public static <T> Result<T> fail(Integer code, String message) {
        return new Result<T>(code, message, null);
    }


}
